package com.example.demo.controller;

import com.example.demo.service.RemoteService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/hello")
public class HelloController {


    @Autowired
    private RemoteService remoteService;

    /**
     * 示例方法
     *
     * @return
     */
    @ApiOperation("本服务接口测试")
    @GetMapping("/hello")
    public String sayHello() {
        return "Hello,This is schedule Service.";
    }

    /**
     * 示例方法：调用服务B
     *
     * @return
     */
    @ApiOperation("远程访问接口测试")
    @GetMapping(path = "/callpaiban")
    public String sayHellopaiban() {
        return remoteService.sayHello();
    }

    @Resource
    private RestTemplate restTemplate;

    @Value("http://175.178.131.223:8400")
    private String serverURL; //服务提供者的服务名

    @ApiOperation("远程访问接口方法2")
    @GetMapping("/callpaiban2")
    public String paymentInfo() {
        return restTemplate.getForObject(serverURL + "/hello/hello" , String.class);
    }

}
